var mongoose = require("mongoose"),
	md5 = require("md5"),
	db = mongoose.connection;
var adminUserSchema = new mongoose.Schema({
		//昵称
		nickname : {type : String , required : true},
		//账号
		account : {type : String , required : true},
		//密码
		password : {type : String , required : true},
		//创建时间
		pubdate : {type : Date , default : new Date , required : true},
		//备注
		remarks : {type : String , required : true}
	});
var adminUserS = db.model("adminuser",adminUserSchema);
//类
function AdminUser(data){
	this.data = {
		account : data && data.account,
		nickname : data && data.nickname,
		password : data && data.password,
		pubdate : data && data.pubdate,
		remarks : data && data.remarks
	};
};
//获取数据
AdminUser.prototype.getUser = function(data , callback){
	if(data){
		adminUserS.find(data , function(err , data){
			if(err){
				callback(err);
			};
			callback(null , data[0]);
		});
	};
};
//保存数据
AdminUser.prototype.create = function(callback){
	var th = this;
	this.data.password = md5(this.data.password);
	//执行数据库添加
	adminUserS.create(this.data , function(error , data){
		if(error){
			return callback(error);
		}else{
			callback && callback(error , data);
		};
	});
};
module.exports = AdminUser;
